package com.huobao.yunying.adapters;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.xutils.common.util.LogUtil;

import com.huobao.yunying.entity.Jiesuan_goods_info;
import com.huobao.yunying.entity.Shipping_methods;
import com.huobao.zhangying.R;

import android.content.Context;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TextView;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Peisong extends QuickAdapter<Shipping_methods> {

	private List<Float> store_freight;
	private float store_total_freight;
	private Jiesuan_goods_info datainfo;
	private Adapter_Jiesuan_ adapter;
	private Set<RadioButton> ebs = new HashSet<RadioButton>();

	public Adapter_Peisong(Context context, List<Shipping_methods> data, List<Float> store_freight,
			float store_total_freight, Jiesuan_goods_info datainfo, Adapter_Jiesuan_ adapter) {
		super(context, R.layout.item_peisong, data);
		this.store_freight = store_freight;
		this.datainfo = datainfo;
		this.adapter = adapter;
		this.store_total_freight = store_total_freight;
		int checkPos = 0;
		for (int i = 0; i < store_freight.size(); i++) {
			float a = store_freight.get(i);
			if (a == store_total_freight) {
				checkPos = i;
			}
		}
		data.get(checkPos).isSelect = true;
		LogUtil.e("checkPos==="+checkPos);
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, final Shipping_methods arg1) {
		TextView tv_price = arg0.getView(R.id.tv_price);
		TextView tv_content = arg0.getView(R.id.tv_content);
		RadioButton checkBox = arg0.getView(R.id.checkbox);
		checkBox.setTag(arg1.fees_id);
		ebs.add(checkBox);
		final float feiyong = store_freight.get(arg0.getPosition());
		tv_price.setText(arg1.name + "费用：￥" + feiyong);
		List<String> xuz = arg1.data;
		tv_content.setText("首重：￥" + xuz.get(0) + "  " + "续重：￥" + xuz.get(1));
//		if(arg1.isSelect){
//			checkBox.setTag(tag);
//		}
		
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					for(Shipping_methods methods : getList()){
						
						if(methods.fees_id.equals(arg1.fees_id)){
							methods.isSelect = true;
						}else{
							methods.isSelect = false;
						}
					}
//					for(RadioButton rb : ebs){
//						if(rb.getTag().equals(arg1.fees_id) == false){
//							rb.setChecked(false);
//						}else{
//							rb.setChecked(true);
//						}
//					}
					datainfo.store_total_freight = feiyong + "";
					adapter.notifyDataSetChanged();
				}
			}
		});
//		checkBox.setonckucj
		if(arg1.isSelect){
			datainfo.store_total_freight = feiyong + "";
		}
		checkBox.setChecked(arg1.isSelect);
	}

}
